<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="/static/backstage/H-ui/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="/static/backstage/H-ui/static/h-ui.admin/css/H-ui.admin.css"/>
    <title>添加管理员 - 管理员管理</title>
</head>
<body>
<article class="page-container">
    <form class="form form-horizontal">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>用户名：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input id="username" type="text" class="input-text">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>初始密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input id="password" type="password" class="input-text" placeholder="密码">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>确认密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input id="confirm-password" type="password" class="input-text" placeholder="确认新密码">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>状态：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    <input name="state" value="1" type="radio" id="state-1" checked>
                    <label for="state-1">启用</label>
                </div>
                <div class="radio-box">
                    <input name="state" value="0" type="radio" id="state-0">
                    <label for="state-0">禁用</label>
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>等级：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input id="level" type="text" class="input-text">
            </div>
        </div>
        <!--
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-3">角色：</label>
                    <div class="formControls col-xs-8 col-sm-9">
                        <span class="select-box" style="width:150px;">
                    <select class="select" name="adminRole" size="1">
                        <option value="0">超级管理员</option>
                        <option value="1">总编</option>
                        <option value="2">栏目主辑</option>
                        <option value="3">栏目编辑</option>
                    </select>
                    </span></div>
                </div>
                -->
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input id="add-btn" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<script type="text/javascript" src="/static/backstage/H-ui/lib/jquery/1.9.1/jquery.min.js"></script>

<script>
    $("#add-btn").click(function () {
        // 收集参数
        let username = $("#username").val().trim();
        let password = $("#password").val().trim();
        let confirm = $("#confirm-password").val().trim();
        let level = $("#level").val().trim();
        let state = $("input[name='state']:checked").val();
        // 表单验证
        if (username == "") {
            alert("用户名不能为空");
            return;
        } else if (password == "") {
            alert("密码不能为空");
            return;
        } else if (confirm == "") {
            alert("确认密码不能为空");
            return;
        } else if (confirm != password) {
            alert("两次密码不一致");
            return;
        } else if (level == "") {
            alert("等级不能为空");
            return;
        }

        $.post("/backstage/user/add", {
            username: username,
            password: password,
            level: level,
            state, state
        }, function (data) {
            if (data.code == "1") {
                // 添加成功
                window.parent.location.reload();//刷新父页面
                let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            } else {
                layer.msg(data.message, {icon: 5, time: 1000});
            }
        });
    });
</script>
</body>
</html>